package cn.com.isfree.tio.server.util;

import java.util.concurrent.atomic.AtomicLong;

public class SynSeqUil {
	/**
	 * 同步发送并发控制使用
	 */
	private static AtomicLong synSeqAtomicLong = new AtomicLong();

	public static int getSynSeqAtomicLong() {
		try {
			int inc = (int) synSeqAtomicLong.incrementAndGet();
			if(inc<1) {//越界判断
				synSeqAtomicLong = new AtomicLong();
				inc = (int) synSeqAtomicLong.incrementAndGet();
			}
			return inc;
		}catch (Exception e) {
			//超出int类型后直接从新统计AtomicLong
			e.printStackTrace();
			synSeqAtomicLong = new AtomicLong();
			return (int) synSeqAtomicLong.incrementAndGet();
		}
		
	}
}
